﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.IRepository.SystemSettings.CommonlyUsedSettings;
using SystemCenterSoa.PoModel.SystemSettings.CommonlyUsedSettings;
using SystemCenterSoa.Repository.CommonLib;

namespace SystemCenterSoa.Repository.SystemSettings.CommonlyUsedSettings
{
    public class BuildingTitleRepository : BaseRepository, IBuildingTitleRepository
    {


        //注入ef的的上下文
        public BuildingTitleRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {


        }
        public int BuildingTitleAdd(BuildingTitlePo info)
        {
            _systemCenterDbSoaContext.BuildingTitle.Add(info);
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public BuildingTitlePo BuildingTitleEdit(int id)
        {
            return _systemCenterDbSoaContext.BuildingTitle.Find(id);
        }

        public int BuildingTitlePoDelete(List<int> ids)
        {
           foreach(var id in ids)
            {
                _systemCenterDbSoaContext.BuildingTitle.Remove(_systemCenterDbSoaContext.BuildingTitle.Find(id));
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int BuildingTitlePoUpdate(BuildingTitlePo info)
        {
            _systemCenterDbSoaContext.Entry(info).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public List<BuildingTitlePo> GetBuildingTitleAll(string name)
        {
            var list = _systemCenterDbSoaContext.BuildingTitle.AsQueryable();
            if (!string.IsNullOrWhiteSpace(name))
            {
                list = list.Where(c => c.building_title_name.Contains(name));
            }
            return list.ToList();
        }
    }
}
